﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DB = HTComics.Data;
using System.Data;
using System.Net.Mail;
using HTComics.Web.Common;

namespace HTComics.Web.User
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnEml_Click(object sender, EventArgs e)
        {
            DataTable dt = DB.HTCUser.GetUserByEmail(txtEmail.Text);

            if (dt.Rows.Count == 0)
            {
                lblError.Text = "Email not found in the system, please try again";
                lblError.Visible = true;
            }
            else
            {
                MailMessage msg = new MailMessage();
                msg.To.Add(dt.Rows[0]["Email"].ToString());
                msg.Subject = "Hidden Treause Comics Account Password";
                msg.Body = "Your password for Hidden Treasure Comics account is " + dt.Rows[0]["Password"].ToString();
                msg.From = new MailAddress(Defaults.MailSetup.NoReplyAccount);
                
                SmtpClient mailClient = new SmtpClient(Defaults.MailSetup.MailServer, Defaults.MailSetup.MailPort);
                mailClient.Send(msg);

                lblError.Text = "Your password has been sent to the email account.";
                lblError.Visible = true;
            }
        }
    }
}